# 解决python获取网页内容乱码问题
##
import  requests

response = requests.get('https://www.baidu.com')
try:
    if response.encoding == 'ISO-8859-1':
        encodings = requests.utils.get_encodings_from_content(response.text)
        if encodings:
            encoding = encodings[0]
        else:
            encoding = response.apparent_encoding
    else:
        encoding = response.encoding
except:
    encoding = "utf-8"
encode_content = response.content.decode(encoding, 'replace').encode('utf-8', 'replace')
encode_content = encode_content.decode(encoding="utf-8", errors='ignore')  # bytes to
if not isinstance(encode_content, str):
    encode_content = encode_content.decode(encoding="utf-8", errors='ignore')
print(encode_content)
